-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test: Fix flaky leader index in waitLeader
function
#188
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Xinyuan Du <[email protected]>
pav-kv
approved these changes
Mar 23, 2024
ahrtr
approved these changes
Mar 23, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Thanks for the fix
nvanbenschoten
added a commit
to nvanbenschoten/cockroach
that referenced
this pull request
Sep 4, 2024
Fixes cockroachdb#127413. This commit bypasses the larger rebase in cockroachdb#122133 to pick up the test flake fix in etcd-io/raft#188. There was some discussion in etcd-io/raft#181 about alternatives for fixing this test. For now, we stick with a direct cherry-pick. Release note: None
nvanbenschoten
added a commit
to nvanbenschoten/cockroach
that referenced
this pull request
Sep 6, 2024
Fixes cockroachdb#127413. This commit bypasses the larger rebase in cockroachdb#122133 to pick up the test flake fix in etcd-io/raft#188. There was some discussion in etcd-io/raft#181 about alternatives for fixing this test. For now, we stick with a direct cherry-pick. Release note: None
craig bot
pushed a commit
to cockroachdb/cockroach
that referenced
this pull request
Sep 6, 2024
130084: raft: fix flaky leader index in waitLeader function r=pav-kv a=nvanbenschoten Fixes #127413. This commit bypasses the larger rebase in #122133 to pick up the test flake fix in etcd-io/raft#188. There was some discussion in etcd-io/raft#181 about alternatives for fixing this test. For now, we stick with a direct cherry-pick. Release note: None Co-authored-by: Nathan VanBenschoten <[email protected]>
nvanbenschoten
added a commit
to nvanbenschoten/cockroach
that referenced
this pull request
Sep 6, 2024
Fixes cockroachdb#127413. This commit bypasses the larger rebase in cockroachdb#122133 to pick up the test flake fix in etcd-io/raft#188. There was some discussion in etcd-io/raft#181 about alternatives for fixing this test. For now, we stick with a direct cherry-pick. Release note: None
nvanbenschoten
added a commit
to nvanbenschoten/cockroach
that referenced
this pull request
Sep 6, 2024
Fixes cockroachdb#127413. This commit bypasses the larger rebase in cockroachdb#122133 to pick up the test flake fix in etcd-io/raft#188. There was some discussion in etcd-io/raft#181 about alternatives for fixing this test. For now, we stick with a direct cherry-pick. Release note: None
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The
waitLeader
function currently has an issue where it returns the wrong leader index in certain scenarios. When iterating through nodes to find the leader, if the leader changes during the iteration, the function incorrectly returns the default value instead of the actual leader index.Example
In the function,
waitLeader
:raft/rafttest/node_test.go
Lines 130 to 151 in e1bfcf7
Let's say,
i
is 3 now, and we still don't have a leader elected.i
is 4 now, and the leader of node[4] has changed from 0 to 1 in step2. Sol[lead] = struct{}{}
will be executed. Butn.id == lead
is false,lindex
still equals 0.len(l)
now equals 1. This function will return lindex, which is 0. But 0 is not the real leader index, but the default value.Proposed Changes
To address this issue, the proposed solution involves initializing the
lindex
variable to -1 instead of 0. This change ensures thatlindex
holds a distinct value indicating 'not found' rather than potentially conflating it with the index of the first element.Changes Made
lindex
variable to -1 instead of 0.Impact
This change ensures that the
waitLeader
function correctly returns the leader index, avoiding confusion between 'not found' and the index of the first element.Fixes #181